﻿using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
using Zenject;

public class RoleSelectUI : MonoBehaviour, IPointerEnterHandler
{
    public Role _role { get; private set; }
    [Header("头像")] [SerializeField] private Image avatarImage;

    [Inject] private GameManager _gameManager;


    /**
     * 初始化单元格、保存对应role数据
     */
    public void InitUI(Role role)
    {
        _role = role;
        if (role.unlock)
        {
            avatarImage.sprite = Resources.Load<Sprite>(role.avatar);
        }
        else
        {
            GetComponent<Button>().interactable = false;
            avatarImage.sprite = Resources.Load<Sprite>("Image/UI/锁");
        }
    }

    public void OnPointerEnter(PointerEventData eventData)
    {
        UpdateRoleInfoUI();
    }

    public void UpdateRoleInfoUI()
    {
        RoleSelectUIManager.Instance.UpdateRoleInfoUI(_role);
    }

    public void SelectRole()
    {
        //记录当前选择的role
        _gameManager.currentRoleBaseData = _role;
        //切换武器选择UI
        RoleSelectUIManager.Instance.SwitchWeaponSelectUI();
        //
        WeaponSelectUIManager.Instance.UpdateRoleInfoUI();
    }
}